package com.china_goldcard.myguideview;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * 引导页对应的adpater
 */
public class MyGuideViewPageAdapter<T extends View> extends PagerAdapter{

    private List<T> views = new ArrayList<>();

    private Context context;

    public MyGuideViewPageAdapter(List<T> views){
        this.views = views;
    }

    public MyGuideViewPageAdapter(){

    }

    /**
     * 重新加载数据
     */
    public void reloadData(List<T> views){
        this.views = views;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return views.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(views.get(position));
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        T view = views.get(position);
        container.addView(view);
        return view;
    }
}
